package com.zryc.shop.sms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zryc.shop.sms.entity.CouponHistory;
import com.zryc.shop.sms.entity.FlashPromotion;
import com.zryc.shop.sms.mapper.CouponHistoryMapper;
import com.zryc.shop.sms.service.ICouponHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 优惠券使用、领取历史表 服务实现类
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@Service
public class CouponHistoryServiceImpl extends ServiceImpl<CouponHistoryMapper, CouponHistory> implements ICouponHistoryService {

    /**
     * 查询使用记录
     *
     * @param pageNum
     * @param pageSize
     * @param couponId
     * @param useStatus
     * @param orderSn
     * @return
     */
    @Override
    public Page<CouponHistory> list(Integer pageNum, Integer pageSize, Long couponId, Integer useStatus, String orderSn) {
        Page<CouponHistory> page = new Page<>(pageNum, pageSize);
        QueryWrapper<CouponHistory> wrapper = new QueryWrapper<>();

        if (!StringUtils.isEmpty(orderSn)) {
            wrapper.like("order_sn", orderSn);
        }
        if (couponId != null) {
            wrapper.eq("coupon_id", couponId);
        }
        if (useStatus != null) {
            wrapper.eq("use_status", useStatus);
        }
        return page(page, wrapper);
    }
}
